package com.kinghood.productcenter.controller.base;

import com.kinghood.infrastructure.api.authority.SysLogModuleEnum;
import com.kinghood.infrastructure.aspect.OperatorLog;
import com.kinghood.infrastructure.model.KingHoodResponseVO;
import com.kinghood.productcenter.common.model.dto.base.AttributeGroupReqDTO;
import com.kinghood.productcenter.service.base.IBaseAttributeGroupService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 属性分租
 * </p>
 *
 * @author KingHood
 * @since 2023-12-26
 */
@RestController
@RequestMapping("/baseAttributeGroup")
public class BaseAttributeGroupController {
    @Resource
    private IBaseAttributeGroupService groupService;

    /**
     * 列表
     *
     * @author jp
     * @date 2023/12/20
     */
    @PostMapping("/listAttributeGroup")
    public KingHoodResponseVO listAttributeGroup(@RequestBody AttributeGroupReqDTO param) {
        return KingHoodResponseVO.success(groupService.listAttributeGroup(param));
    }


    /**
     * 新增更新
     *
     * @param dirReq
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_ATTRIBUTE,content = "属性管理-新增、修改属性组")
    @PostMapping(value = "/addOrUpdateAttributeGroup")
    public KingHoodResponseVO addOrUpdateAttributeGroup(@Valid @RequestBody AttributeGroupReqDTO dirReq){
        groupService.addorUpdateAttributeGroup(dirReq);
        return KingHoodResponseVO.success();
    }


    /**
     * 根据id删除
     *
     * @param id id
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_ATTRIBUTE,content = "属性管理-删除属性组")
    @RequestMapping(value = "/delAttributeGroup/{id}")
    public KingHoodResponseVO delAttributeGroup(@PathVariable("id") Long id){
        groupService.delAttributeGroupById(id);
        return KingHoodResponseVO.success();
    }


    /**
     * 根据ID查询详情
     *
     * @param id id
     * @author jp
     * @date 2023/12/21
     */
    @PostMapping(value = "/detailAttributeGroup/{id}")
    public KingHoodResponseVO detailAttributeGroup(@PathVariable("id") Long id){
        return KingHoodResponseVO.success(groupService.detailAttributeGroup(id));
    }
}
